package service;

import dao.ItemDao;
import entity.Item;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by gwei on 2017/5/27.
 */
@WebServlet(name = "AdminServlet",urlPatterns = "/admin")
public class AdminServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        session.setAttribute("active",3);
        User user = (User)session.getAttribute("user");
        ItemDao itemDao = new ItemDao();
        List itemList = itemDao.getItemList(user.getId());
        request.setAttribute("itemList",itemList);
        request.getRequestDispatcher("/WEB-INF/view/admin.jsp").forward(request,response);
        return;
    }

    private boolean isLogin(HttpSession session) {
        return session.getAttribute("user") != null;
    }
}
